VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsModuleNumber"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Option Base 1

Private Const Quote As String = """"
Private Const BaseErrorCode As Long = &H100

'only judge pure number like 123 1.23 133.4
Public Function IsNumber(ByVal Char As String) As Boolean
    Dim asciiCode As Long
    asciiCode = Asc(Char)
    IsNumber = (asciiCode >= Asc("0") And asciiCode <= Asc("9"))
End Function

' 123 .23 &h2 &H2 &Hf025
Public Sub ProcessNumber(Token As clsToken, Provider As clsCodeProvider)
    Dim sChar As String
    Dim sStateCode As String
    Provider.StepBack
    Do While Provider.CanContinue
        sChar = Provider.GetNextChar
        Select Case sChar
            Case "0" To "9"
                If sStateCode = "" Then
                    sStateCode = "s3"
                    Token.PushChar sChar
                Else
                    Token.PushChar sChar
                End If
            Case "a" To "f", "A" To "F"
                If sStateCode = "s1" Then
                    Token.PushChar sChar
                Else
                    pmRaise "Error parsing number at " & Provider.Line
                End If
            Case "&"
                If sStateCode = "" Then
                    If Provider.MatchNextChar("H", "") Or Provider.MatchNextChar("h", "") Then
                        sStateCode = "s1"
                        Token.PushChar "&H"
                    Else
                        pmRaise "Error parsing number at " & Provider.Line
                    End If
                ElseIf sStateCode = "s3" Then
                    Token.PushChar sChar
                    Exit Do
                End If
            Case "."
                If sStateCode = "" Then
                    sStateCode = "s2"
                    Token.PushChar "0."
                ElseIf sStateCode = "s3" Then
                    sStateCode = "s2"
                    Token.PushChar sChar
                Else
                    pmRaise "Error parsing number at " & Provider.Line
                End If
            Case " "
                If sStateCode = "s1" Then
                    Exit Do
                ElseIf sStateCode = "s2" Then
                    Exit Do
                ElseIf sStateCode = "s3" Then
                    Exit Do
                Else
                    pmRaise "Error parsing number at " & Provider.Line
                End If
            Case "#"
                If sStateCode = "s2" Then
                    Exit Do
                ElseIf sStateCode = "s3" Then
                    Token.PushChar sChar
                    Exit Do
                End If
            Case "%"
                If sStateCode = "s3" Then
                    Exit Do
                Else
                    pmRaise "Error parsing number at " & Provider.Line
                End If
            Case ")"
                Provider.StepBack
                Exit Do
            Case Chr(13)
                Provider.StepBack
                Exit Do
            Case Else
                pmRaise "Error parsing number at " & Provider.Line
        End Select
    Loop
    Token.TokenType = Number
End Sub

Private Sub pmRaise(ByVal pMessage As String)
    Err.Raise vbObjectError + BaseErrorCode, "clsModuleNumber", pMessage
End Sub

